document.getElementsByClassName = function(clsName)
{
	var retVal = new Array();
	
	var elements = document.getElementsByTagName("*");
	for (var i = 0; i < elements.length; i++)
	{
		if (elements[i].className.indexOf(" ") >= 0)
		{
			var classes = elements[i].className.split(" ");
			for (var j = 0; j < classes.length; j++)
			{
				if(classes[j] == clsName)
				{
					retVal.push(elements[i]);
				}
			}
		}
		else if(elements[i].className == clsName)
		{
			retVal.push(elements[i]);
		}
	}
	
	return retVal;
}

function createBookmark(title, url)
{
	if (window.sidebar) // Mozilla Firefox Bookmark
	{
		window.sidebar.addPanel(title, url, "");
	}
	else if (window.external) // IE Favorite
	{
		window.external.AddFavorite(url, title);
	}
	else if (window.opera && window.print) // Opera Hotlist
	{
		return true;
	}
}

function replaceAPIURLParams(str, attr, val)
{
	// we need to escape any backslash when using the RegExp constructor, else we get a syntax error on the regex, so in this case, we will have 2 backslashes for 1 escaped character
	// we use the RegExp constructor here to be able to put variables
	// this regular expression is used to replace both the toolbar button and the api url
	var re = new RegExp("(&(amp;)?" + attr + "=('\\+e\\(')?)[^&\\)']*(('\\)\\+')?&(amp;)?)", "gi");
	return str.replace(re, "$1" + val + "$4");
}

function changeAPIURLParams(obj, attr)
{
	var shortcut = document.getElementById("shortcut");
	var apiurl = document.getElementById("api_url");
	
	var newVal = obj.options[obj.selectedIndex].value;
	ToolbarButton[attr] = newVal;
	
	shortcut.innerHTML = ToolbarButton.getName();
	shortcut.href = unescape(replaceAPIURLParams(shortcut.href, attr, newVal));
	
	apiurl.innerHTML = replaceAPIURLParams(apiurl.innerHTML, attr, "<b>" + newVal + "</b>");
}

// display a flash object for a XHTML 1.0 Strict valid document
// i decide to create a object tag dynamically to be able to call the encodeURIComponent function
// i do not use a tool like SWFObject because when i hold down the mouse and go outside of the flash, it keeps the button pushed down, embed tags seem to do that, not object tags
function createCopyButton(text)
{
	document.write("<object type='application/x-shockwave-flash' data='/swf/clipboard.swf' width='100' height='20'>\n");
	document.write("<param name='movie' value='/swf/clipboard.swf' />\n");
	document.write("<param name='flashvars' value='text=" + encodeURIComponent(text) + "' />\n");
	document.write("</object>\n");
}

// resize the content div's height to be equal to the left div's height
function resizeContentDiv()
{
	var content = document.getElementById("content");
	var left = document.getElementById("left");

	// if the content section's height is lower than the left section's height, increase the content section's height so they can be aligned at the bottom
	if (content.offsetHeight < left.offsetHeight)
	{
		var path = document.getElementById("path");
		var main = document.getElementById("main");
		
		var height = left.offsetHeight - content.offsetHeight + main.offsetHeight - path.offsetHeight;
		main.style.height = height + "px";
		
		// fix for Firefox and Google Chrome: in some pages, the main div's height exceed of one pixel, decrease the content section's height so they can be aligned at the bottom
		while (content.offsetHeight > left.offsetHeight)
		{
			main.style.height = --height + "px";
		}
	}
}

function externalLinks()
{
	if (!document.getElementsByTagName)
	{
		return;
	}
	
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && !/^javascript:/i.test(anchor.getAttribute("href")))
		{
			if (window.parent.frames.length > 0) // if we are in a frame, open links in parent window (used in preview mode)
			{
				anchor.target = "_parent";
			}
			else if (anchor.getAttribute("rel") == "external") // XHTML 1.0 Strict valid attribute for opening links in new window
			{
				anchor.target = "_blank";
			}
		}
	}
}

window.onload = externalLinks;